package com.hb.trade.api.routine.controller.project.opening;

import com.hb.core.pojo.project.opening.dto.OpeningSetDTO;
import com.hb.trade.client.project.BidOpeningClient;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.fzzn.core.auth.shiro.util.ShiroUtil;
import org.fzzn.core.model.enums.MsgEnum;
import org.fzzn.core.model.msg.ResponseDto;
import org.fzzn.core.model.user.login.LoginUser;
import org.fzzn.core.util.ResultUtil;
import org.fzzn.core.web.anno.Version;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 开标相关Api控制层
 *
 * @author Lix1ang
 * @date 2021-12-10 11:24:50
 */
@Version(1.0)
@RestController
@RequestMapping("/{version}")
@Api(tags = "开标设置", value = "bidOpeningTemplate")
public class ApiBidOpeningController {

    protected final BidOpeningClient bidOpeningClient;

    public ApiBidOpeningController(BidOpeningClient bidOpeningClient) {
        this.bidOpeningClient = bidOpeningClient;
    }

    //----------------------------------------- 开标设置业务模块 ----------------------------------------------

    @ApiOperation(value = "查询开标设置列表", httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "projectId", value = "项目ID", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "hostName", value = "开标人", dataTypeClass = String.class),
            @ApiImplicitParam(name = "status", value = "状态:(0:已保存 1:开启 2:审核中 3:审核不通过)", dataTypeClass = Integer.class)
    })
    @PostMapping("/openingSet/pageOpeningSet")
    public ResponseDto pageOpeningSet(@RequestBody OpeningSetDTO openingSet) {
        return ResultUtil.msg(bidOpeningClient.pageOpeningSet(openingSet));
    }

    @ApiOperation(value = "获取未选择的标段", httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "projectId", value = "项目ID", dataTypeClass = Long.class)
    })
    @PostMapping("/openingSet/getSectionNotSelected")
    public ResponseDto getSectionNotSelected(@RequestBody OpeningSetDTO openingSet) {
        return ResultUtil.msg(bidOpeningClient.getSectionNotSelected(openingSet));
    }

    @ApiOperation(value = "设置监标人", httpMethod = "POST")
    @PostMapping("/openingSet/setSupervisor")
    public ResponseDto setSupervisor(@RequestBody OpeningSetDTO openSet) {
        LoginUser<Long> loginUser = ShiroUtil.getUser();
        if (null == loginUser) {
            return ResultUtil.fail(MsgEnum.LOGIN_EXPIRE);
        }
        ShiroUtil.fillOwner(openSet);
        return ResultUtil.msg(bidOpeningClient.setSupervisor(openSet));
    }

    @ApiOperation(value = "保存开标设置", httpMethod = "POST")
    @PostMapping("/openingSet/save")
    public ResponseDto save(@RequestBody OpeningSetDTO openSet) {
        LoginUser<Long> loginUser = ShiroUtil.getUser();
        if (null == loginUser) {
            return ResultUtil.fail(MsgEnum.LOGIN_EXPIRE);
        }
        ShiroUtil.fillOwner(openSet);
        return ResultUtil.msg(bidOpeningClient.save(openSet));
    }

    @ApiOperation(value = "申请开启", httpMethod = "POST")
    @PostMapping("/openingSet/openApply")
    public ResponseDto openApply(@RequestBody OpeningSetDTO openSet) {
        return ResultUtil.msg(bidOpeningClient.openApply(openSet));
    }

    @ApiOperation(value = "审核", httpMethod = "POST")
    @PostMapping("/openingSet/approved")
    public ResponseDto approved(@RequestBody OpeningSetDTO openSet) {
        return ResultUtil.msg(bidOpeningClient.approved(openSet));
    }

    @ApiOperation(value = "详情", httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "标段ID", required = true, dataTypeClass = String.class)
    })
    @PostMapping("/openingSet/detail")
    public ResponseDto detail(@RequestBody OpeningSetDTO openSet) {
        return ResultUtil.msg(bidOpeningClient.detail(openSet));
    }

    @ApiOperation(value = "审核列表", httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "status", value = "状态:(0:已保存 1:开启 2:审核中 3:审核不通过)", dataTypeClass = String.class),
            @ApiImplicitParam(name = "projectId", value = "项目ID", dataTypeClass = int.class)
    })
    @PostMapping("/openingSet/applyList")
    public ResponseDto applyList(@RequestBody OpeningSetDTO openSet) {
        return ResultUtil.msg(bidOpeningClient.applyList(openSet));
    }

}
